package com.hj.aiminai.docment;

import lombok.Data;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;

@Data
@Document("chat")
public class Msg {
    private String text;
    private String type;
    private Date date;
    private String conversationId;

    public Msg(String conversationId, Message message) {
        this.conversationId = conversationId;
        this.text = message.getText();
        this.type = message.getMessageType().getValue();
        this.date = new Date();

    }

    public static Message toMessage(Msg msg){
        return switch (msg.getType()){
            case "user" ->new UserMessage(msg.getType());
            case "assistant" ->new AssistantMessage(msg.getType());
            case "system" ->new SystemMessage(msg.getType());
            default -> null;
        };
    }
}
